<template>
  <div class="index-container">
    <el-row :gutter="20">
      <el-col
        v-for="(item, index) in iconList"
        :key="index"
        :lg="4"
        :md="4"
        :sm="4"
        :xl="4"
        :xs="12"
      >
        <el-card class="icon-panel" shadow="hover">
          <div
            style="
              display: flex;
              flex-direction: column;
              align-items: center;
              justify-content: center;
            "
            @click="getData1(index)"
          >
            <el-badge :value="item.value">
              <vab-icon
                :icon="item.icon"
                :style="{ color: item.color, fontSize: '40px' }"
              />
            </el-badge>
            <p>{{ item.title }}</p>
          </div>
        </el-card>
      </el-col>

      <el-col :lg="16" :md="16" :sm="16" :xl="16" :xs="16">
        <el-card class="access" shadow="hover" skeleton>
          <div class="card-header" slot="header">
            <div>
              <vab-icon icon="tools-fill" />
              待维修设备清单
            </div>
          </div>
          <!-- <vab-query-form>
            <vab-query-form-left-panel :span="12"></vab-query-form-left-panel>
            <vab-query-form-right-panel :span="12">
              <el-form :inline="true" :model="queryForm" @submit.native.prevent>
                <el-form-item>
                  <el-input
                    v-model.trim="queryForm.MatchString"
                    clearable
                    placeholder="请输入"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    icon="el-icon-search"
                    type="primary"
                    @click="queryData"
                  >
                    查询
                  </el-button>
                </el-form-item>
              </el-form>
            </vab-query-form-right-panel>
          </vab-query-form> -->
          <el-table :data="list1" style="width: 100%">
            <el-table-column label="设备编号" prop="DeviceId" />
            <el-table-column label="设备名称" prop="DeviceName" />
            <el-table-column label="维修状态" prop="State">
              <template slot-scope="scope">
                <template v-if="scope.row.State == '已维修'">
                  <el-tag class="ml-2" type="success">已完成</el-tag>
                </template>
                <template v-else>
                  <el-tag class="ml-2" type="danger">未完成</el-tag>
                </template>
              </template>
            </el-table-column>
            <el-table-column label="型号" prop="DeviceModel" />
            <el-table-column label="故障内容" prop="Content" />
            <el-table-column label="厂内负责人" prop="Director" />
            <el-table-column label="负责人手机号" prop="DirectorPhoneNo" />
            <el-table-column
              align="center"
              label="操作"
              show-overflow-tooltip
              width="200"
            >
              <template slot-scope="scope">
                <el-button text type="primary" @click="handleQue(scope.row, 1)">
                  维修完成
                </el-button>
              </template>
            </el-table-column>
            <template slot="empty">
              <el-empty class="vab-data-empty" description="暂无数据" />
            </template>
          </el-table>
          <el-pagination
            background
            :current-page="queryForm1.pageNo"
            :layout="layout"
            :page-size="queryForm1.pageSize"
            :total="total1"
            @current-change="handleCurrentChange1"
            @size-change="handleSizeChange1"
          />
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :lg="24" :md="24" :sm="24" :xl="24" :xs="24">
        <el-card class="access" shadow="hover" skeleton>
          <div class="card-header" slot="header">
            <div>
              <vab-icon icon="tools-fill" />
              维修记录
            </div>
          </div>
          <!-- <vab-query-form>
            <vab-query-form-left-panel :span="12"></vab-query-form-left-panel>
            <vab-query-form-right-panel :span="12">
              <el-form :inline="true" :model="queryForm" @submit.native.prevent>
                <el-form-item>
                  <el-input
                    v-model.trim="queryForm.MatchString"
                    clearable
                    placeholder="请输入"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    icon="el-icon-search"
                    type="primary"
                    @click="queryData"
                  >
                    查询
                  </el-button>
                </el-form-item>
              </el-form>
            </vab-query-form-right-panel>
          </vab-query-form> -->
          <el-table :data="list2" style="width: 100%">
            <el-table-column label="设备编号" prop="DeviceId" />
            <el-table-column label="设备名称" prop="DeviceName" />
            <el-table-column label="维修状态" prop="State">
              <template slot-scope="scope">
                <template v-if="scope.row.State == '已维修'">
                  <el-tag class="ml-2" type="success">已完成</el-tag>
                </template>
                <template v-else>
                  <el-tag class="ml-2" type="danger">未完成</el-tag>
                </template>
              </template>
            </el-table-column>
            <el-table-column label="型号" prop="DeviceModel" />
            <el-table-column label="维修内容" prop="Content" />
            <el-table-column label="厂内负责人" prop="Director" />
            <el-table-column label="负责人手机号" prop="DirectorPhoneNo" />
            <!-- <el-table-column
              align="center"
              label="操作"
              show-overflow-tooltip
              width="200"
            >
              <template slot-scope="scope">
                <el-button text type="primary" @click="handleQue(scope.row, 2)">
                  维修完成
                </el-button>
              </template>
            </el-table-column> -->
            <template slot="empty">
              <el-empty class="vab-data-empty" description="暂无数据" />
            </template>
          </el-table>
          <el-pagination
            background
            :current-page="queryForm2.pageNo"
            :layout="layout"
            :page-size="queryForm2.pageSize"
            :total="total2"
            @current-change="handleCurrentChange2"
            @size-change="handleSizeChange2"
          />
        </el-card>
      </el-col>
    </el-row>

    <el-dialog
      :close-on-click-modal="false"
      :visible="dialogVisible"
      :title="title"
      width="60%"
      :before-close="handleClose"
    >
      <div>
        <el-table :data="filterTableData" style="width: 100%">
          <el-table-column label="设备编号" prop="DeviceId" />
          <el-table-column label="设备名称" prop="DeviceName" />
          <el-table-column label="维修状态" prop="State">
            <template #default="scope">
              <template v-if="scope.row.State == '已维修'">
                <el-tag class="ml-2" type="success">已完成</el-tag>
              </template>
              <template v-else>
                <el-tag class="ml-2" type="danger">未完成</el-tag>
              </template>
            </template>
          </el-table-column>
          <el-table-column label="型号" prop="DeviceModel" />
          <el-table-column label="维修内容" prop="Content" />
          <el-table-column label="厂内负责人" prop="Director" />
          <el-table-column label="负责人手机号" prop="DirectorPhoneNo" />
          <el-table-column
            align="center"
            label="操作"
            show-overflow-tooltip
            width="200"
            v-if="index == 0"
          >
            <template slot-scope="scope">
              <el-button text type="primary" @click="handleQue(scope.row)">
                维修完成
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <template slot="footer">
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import {
    InformationStatistics,
    DeviceFaultInfo,
    RepairRecord,
    IsOkButtonClick,
  } from '@/api/equipment'

  export default {
    data() {
      return {
        iconList: [
          {
            icon: 'picture-in-picture-2-line',
            title: '正在维修',
            link: '',
            color: '#95de64',
          },
          {
            icon: 'picture-in-picture-exit-line',
            title: '累计维修',
            link: '',
            color: '#69c0ff',
          },
        ],
        queryForm1: {
          pageNo: 1,
          pageSize: 10,
          MatchString: '',
        },
        total1: 0,
        list1: [],

        queryForm2: {
          pageNo: 1,
          pageSize: 10,
          MatchString: '',
        },
        total2: 0,
        list2: [],

        dialogVisible: false,
        Type: '',
        layout: 'total, sizes, prev, pager, next, jumper',

        filterTableData: [],
        tableData: [],
        title: '设备',

        index: 0,
      }
    },
    created() {
      this.initData()
    },
    methods: {
      getData1(index) {
        this.index = index
        const params = {
          Index: 0,
          Count: 10,
          State: index === 1 ? '已维修' : '未维修',
        }
        RepairRecord(params).then((res) => {
          console.log(res)
          this.filterTableData = res.RepairRecordInfo
          this.total = res.TotalCount
          this.dialogVisible = true
        })
      },
      handleQue(row, index) {
        console.log('row', row)
        IsOkButtonClick({ RepairId: row.RepairId }).then((res) => {
          if (index == 1) {
            this.fetchData1()
          } else {
            this.getData1(0)
          }
        })
      },
      handleEdit(index, row) {
        OkButtonClick({ MainrenanceId: row.MainrenancePlanId }).then((res) => {
          console.log(res)
          initData()
        })
      },
      handleClose() {
        this.dialogVisible = false
      },
      handleSizeChange1(val) {
        this.queryForm1.pageSize = val
        this.fetchData1()
      },
      handleCurrentChange1(val) {
        this.queryForm1.pageNo = val
        this.fetchData1()
      },
      handleSizeChange2(val) {
        this.queryForm2.pageSize = val
        this.fetchData2()
      },
      handleCurrentChange2(val) {
        this.queryForm2.pageNo = val
        this.fetchData2()
      },
      queryData() {
        this.queryForm.pageNo = 1
        this.fetchData()
      },
      fetchData1() {
        this.listLoading = true
        const params = {
          Index: this.getPage(this.queryForm1.pageNo, this.queryForm1.pageSize),
          Count: this.queryForm1.pageSize,
          MatchString: this.queryForm1.MatchString,
          State: '未维修',
        }
        RepairRecord(params).then((res) => {
          this.list1 = res.RepairRecordInfo
          this.total1 = res.TotalCount
          this.listLoading = false
        })
      },
      fetchData2() {
        this.listLoading = true
        const params = {
          Index: this.getPage(this.queryForm2.pageNo, this.queryForm2.pageSize),
          Count: this.queryForm2.pageSize,
          MatchString: this.queryForm2.MatchString,
          State: '未维修',
        }
        DeviceFaultInfo(params).then((res) => {
          this.list2 = res.RepairRecordInfo
          this.total2 = res.TotalCount
          this.listLoading = false
        })
      },
      getData() {
        //设备保养信息统计
        InformationStatistics().then((res) => {
          this.iconList[0].value = res.Repairing
          this.iconList[1].value = res.AccumulateRepairs
        })
      },
      initData() {
        this.getData()
        this.fetchData1()
        this.fetchData2()
      },
    },
  }
</script>

<style lang="scss" scoped>
  .index-container {
    padding: 0 !important;
    background: $base-color-background !important;

    :deep() {
      .access,
      .authorization,
      .version-information {
        min-height: 268px;
      }

      .el-card {
        .el-card__header {
          position: relative;

          .card-header-tag {
            position: absolute;
            top: 15px;
            right: $base-margin;
          }

          > div > span {
            display: flex;
            align-items: center;

            i {
              margin-right: 3px;
            }
          }
        }

        .el-card__body {
          position: relative;

          .echarts {
            width: 100%;
            height: 127px;
          }

          .card-footer-tag {
            position: absolute;
            right: $base-margin;
            bottom: 15px;
          }
        }
      }

      .bottom {
        padding-top: 20px;
        margin-top: 5px;
        color: #595959;
        text-align: left;
        border-top: 1px solid $base-border-color;
      }
    }
  }
</style>
